//
//  PTTeacherMessageView.m
//  PT
//
//  Created by yate1996 on 15/6/19.
//  Copyright (c) 2015年 jarze. All rights reserved.
//

#import "PTTeacherMessageView.h"
#import "MeItem.h"
#import "ReceiveViewController.h"
@interface PTTeacherMessageView ()



@end
@implementation PTTeacherMessageView



- (void)setMeItem:(MeItem *)meItem
{
    
    _meItem = meItem;
    

    self.teacherNameLabel.text = self.meItem.teacherName;
    
    self.teacherScoreLabel.text = self.meItem.teacherScore;
    
    self.teacherIconView.image = [UIImage imageNamed:self.meItem.teacherIcon];
    
    CGFloat iconX = 1.5 * PTRecorderCellInset;
    CGFloat iconY = 1.5 * PTRecorderCellInset;
    CGFloat iconW = 60;
    CGFloat iconH = 60;
    self.teacherIconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
    
    
    CGFloat titleX = CGRectGetMaxX(self.teacherIconView.frame) + 15;
    CGFloat titleY = iconY + 5;
    NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
    textAttr[NSFontAttributeName] = PTHelveticaNeueLight14;
    CGSize titleSize = [self.meItem.teacherName sizeWithAttributes:textAttr];
    self.teacherNameLabel.frame = (CGRect){{titleX,titleY},titleSize};
    
    self.teacherValueView = [self setupSetValue:4.5];
    self.teacherValueView.frame = CGRectMake(titleX, CGRectGetMaxY(self.teacherNameLabel.frame) + PTRecorderCellMargin * 0.7 , self.teacherValueView.width,self.teacherValueView.height);
    [self addSubview:self.teacherValueView];
    
    
    CGFloat nameX = titleX;
    CGFloat nameY = CGRectGetMaxY(self.teacherValueView.frame) + PTRecorderCellMargin * 0.7;
    textAttr[NSFontAttributeName] = PTRecorderlessonTitleFont
    titleSize = [self.meItem.teacherScore sizeWithAttributes:textAttr];
    self.teacherScoreLabel.frame = (CGRect){{nameX,nameY},titleSize};
    
    _cellHeight = CGRectGetMaxY(self.teacherIconView.frame) + 1.5 * PTRecorderCellInset;
    self.rightArrowButton.frame = CGRectMake(320 - _cellHeight, 0, _cellHeight, _cellHeight);

    self.backgroundColor = [UIColor whiteColor];
}


//教师评分
-(UIView *)setupSetValue:(CGFloat  )teacherScore
{
    
    UIView *teacherValue = [[UIView alloc]init];
    
    //空星级imageView
    _starEmptyImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"emptyStars@2x"]];
    _starEmptyImageView.frame = CGRectMake(0,0,_starEmptyImageView.image.size.width,_starEmptyImageView.image.size.height);
    _starEmptyImageView.userInteractionEnabled=YES;
    [teacherValue addSubview:_starEmptyImageView];
    
    _starImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Stars@2x"]];
    
    _starImageView.frame=CGRectMake(0,0,teacherScore * _starEmptyImageView.width / 5.0,_starEmptyImageView.height);
    _starImageView.contentMode=UIViewContentModeLeft;
    _starImageView.clipsToBounds=YES;
    
    teacherValue.frame = CGRectMake(0, 0, _starEmptyImageView.width, _starEmptyImageView.height);
    [teacherValue addSubview:_starImageView];
    
    return teacherValue;
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if(self) {
        
        UILabel *teacherNameLabel = [[UILabel alloc]init];
        teacherNameLabel.font = PTHelveticaNeueLight14;
        [self addSubview:teacherNameLabel];
        self.teacherNameLabel = teacherNameLabel;
        
        UIImageView *teacherIconView = [[UIImageView alloc]init];
        [self addSubview:teacherIconView];
        self.teacherIconView = teacherIconView;
        
        UILabel *teacherScoreLabel = [[UILabel alloc]init];
        teacherScoreLabel.font = PTRecorderlessonTitleFont;
        [self addSubview:teacherScoreLabel];
        [self.teacherScoreLabel setTextColor:[UIColor lightGrayColor]];
        self.teacherScoreLabel = teacherScoreLabel;
        
    }
    
    UIButton *rightArrowButton = [[UIButton alloc]init];
    [rightArrowButton setImage:[UIImage imageNamed:@"ico_arrow_right"] forState:UIControlStateNormal];
    self.rightArrowButton = rightArrowButton;
    [self addSubview:rightArrowButton];
    

    return self;
}


@end
